package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.selectUserDaocy;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class selectUserDaoImplcy implements selectUserDaocy {

	@Override
	public JSONArray getSelectUser() {
		JSONArray js=new JSONArray();
		StringBuffer sql=new StringBuffer();
		sql.append(" SELECT `user`.uname,`user`.uid FROM `user`");
		sql.append(" WHERE `user`.rid IS NULL");
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			ResultSet rs=pst.executeQuery();
			while(rs.next()){
				JSONObject p =new JSONObject();
				p.put("id", rs.getInt("uid"));
				p.put("text", rs.getString("uname"));
				js.add(p);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return js;
	}

	@Override
	public JSONArray getSelectRole() {
		JSONArray js=new JSONArray();
		StringBuffer sql=new StringBuffer();
		sql.append(" SELECT role.rid, role.rname FROM `role`");
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			ResultSet rs=pst.executeQuery();
			while(rs.next()){
				JSONObject p =new JSONObject();
				p.put("id", rs.getInt("rid"));
				p.put("text", rs.getString("rname"));
				js.add(p);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return js;
	}

}
